<?php

namespace App\Inventor\Controllers;

use App\Repositories\BookApplyRepository;
use App\Services\BookApplyService;
use Encore\Admin\Facades\Admin;


class BookApplyController extends BaseApplyController
{
    protected $title = '软件著作权申请';
    public $repository;
    protected $service;

    public function __construct(BookApplyRepository $repository, BookApplyService $service)
    {
        parent::__construct($repository, $service);
        $this->repository = $repository;
        $this->service = $service;
    }

    protected function grid($action)
    {
        $grid = $this->repository->grid();
        $user = Admin::user();
        $grid->model()->where(function ($query) use ($user) {
            $user_name = $user['name'];
            $query->where('user_id', $user->id)->orWhere('inventor','like',"%$user_name%");
        })->orderByDesc('id');
        if ($action == 'grant') {
            $this->service->gridPublishColumns($grid);
        } else {
            $this->service->gridColumns($grid);
            $grid->model()->where('status', 0);
        }
        $grid->hiddenColumns = [];
        return $grid;
    }
}
